Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

errorex

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errorex

'Extensible Error Class' implementation and predefined additional error types for javascript

  • 2.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-29.46%
Maintainers
1
Weekly downloads
 
Created
Source

ErrorEx

NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

'Extensible Error Class' implementation and predefined additional error types for javascript.

Installation

$ npm install errorex --save

Usage

var {ErrorEx, RangeError} = require('errorex');

var error = new erx.RangeError('Value out of range')
        .setMinValue(1)
        .setMaxValue(5);
console.log(error.message);                    // Value out of range
console.log(error instanceof Error);           // true
console.log(error instanceof erx.RangeError);  // true
console.log(error.toString());                 // RangeError: Value out of range
console.log(error.minValue);                   // 1
console.log(error.maxValue);                   // 5
console.log(error.stack);                      // Prints stack trace

Extending custom error classes in ES6

class MyError extends ErrorEx {
 constructor(...args) {
   super(...args);
   this.myproperty = 1000;
 }
 
 setFoo(val) {
   this.set('foo', val);
 }
}


throw new MyError('My message %d', 10)
.setFoo('fooooo')
.set({
  prop1: 1,
  prop2: 2
});

Extending custom error classes in ES5


function MyError() {
  ErrorEx.apply(this, arguments);
  this.myproperty = 1000;
}
MyError.prototype = Object.create(ErrorEx.prototype);
MyError.prototype.constructor = MyError;
MyError.prototype.setFoo = function(val) {
  this.set('foo', val);
};


throw new MyError('My message %d', 10).setFoo('fooooo');

Predefined error classes

  • ErrorEx: Base error class

  • ArgumentError: Extending from ErrorEx

  • RangeError: Extending from ErrorEx

  • HttpError: Extending from ErrorEx

  • HttpClientError: Extending from HttpError

  • HttpServerError: Extending from HttpError

Node Compatibility

  • node >= 0.10;

License

MIT

Keywords

FAQs

Package last updated on 08 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc